<?php
/*
 * @Author: Wulala
 * @Date: 2025-04-08 11:46:09
 * @LastEditTime: 2025-04-15 16:40:30
 * @LastEditors: Wulala
 * @Description: 
 * @FilePath: \exchange\app\admin\service\ShopService.php
 * 可以输入预定的版权声明、个性签名、空行等
 */

namespace app\admin\service;

use think\facade\Cache;
use GuzzleHttp\Client;
use app\admin\model\AppInterfaceConfig as AppInterfaceConfigModel;

// 商城服务类
class ShopService
{

    // 通知发货
    public static function sendGoods($appid,$order_no,$post)
    {
        $url=  (new AppInterfaceConfigModel)->where('appid',$appid)->value('send_goods_notice');
        if(!$url){
            return ['code'=>0,'msg'=>'请在后台配置发货通知地址'];
        }

        // 调用第三方接口
        $jsonData['order_no']=$order_no;//订单号
        $jsonData['status']=1;//已发货
        $jsonData['send_type']=$post['send_type'];//1需要物流2不需要
        $jsonData['express_info']=$post['express_info'];//快递信息
        $jsonData['express_money']=$post['express_money'];//快递金额
        $jsonData['send_remark']=$post['send_remark'];//发货备注

        $client = new Client();
        $response = $client->request('POST', $url, [
            'form_params' => $jsonData
        ]);
        $body = $response->getBody()->getContents();

        return json_decode($body,true);
    }

    // 通知转账
    public static function payCash($appid,$order_no,$pay_num,$send_remark)
    {
        $url=  (new AppInterfaceConfigModel)->where('appid',$appid)->value('pay_cash_notice');
        if(!$url){
            return ['code'=>0,'msg'=>'请在后台配置发货通知地址'];
        }

        // 调用第三方接口
        $jsonData['appid']=$appid;//appid
        $jsonData['order_no']=$order_no;//订单号
        $jsonData['status']=1;//已转账
        $jsonData['pay_num']=$pay_num;//转账单号
        $jsonData['send_remark']=$send_remark;//发货备注

        $client = new Client();
        $response = $client->request('POST', $url, [
            'form_params' => $jsonData
        ]);
        $body = $response->getBody()->getContents();

        return json_decode($body,true);
    }

}